import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;



public class ServerSocketTest {

	public static void main(String[] args){
		try {
			ServerSocket server = new ServerSocket(4700);
			System.out.println("server start........................");
			System.out.println("wait client................");
			Socket socket = server.accept();
			System.out.println("client connect server............");
			
			BufferedReader bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			PrintWriter pw = new PrintWriter(socket.getOutputStream());
			//System.out.println(bufr.readLine());
			while(!"bye".equals(bufr.readLine())){
				System.out.println(bufr.readLine());
				String str = "sssssssss" + "===" + System.currentTimeMillis() / 1000;
				pw.println(str);
				pw.flush();
				System.out.println(str);
			}
			
			
//			BufferedReader bufr_system_in = new BufferedReader(new InputStreamReader(System.in));
//			boolean flag = true;
//			while(flag){
//				// out print
//				String serverMeg = bufr_system_in.readLine();
//				while(serverMeg != null){
//					outPrint.println(serverMeg);
//					outPrint.flush();
//					System.out.println("Server:" + serverMeg);
//					if("bye".equals(serverMeg)){
//						flag = false;
//					}
//				}
//				//in print
//				String clientMeg = bufr.readLine();
//				while(clientMeg != null){
//					System.out.println("Cleint:" + clientMeg);
//				}
//			}
			
			socket.close();
			server.close();
			System.out.println("shut down........................");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

